package com.lza.handle;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.lza.phone.entity.Phone;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 *
 * 集中处理添加删除的类,自动填充多项野和手机id一样
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Autowired
    Phone voPhone;
    @Override
    public void insertFill(MetaObject metaObject) {//自动填充时间
        this.setFieldValByName("listingDate", new Date(), metaObject);//创建时间
       // this.setFieldValByName("modified", new Date(), metaObject);//修改时间
        /*this.setFieldValByName("screenId", voPhone.getId(), metaObject);//使屏幕id和手机id一样
        this.setFieldValByName("sizeId", voPhone.getId() , metaObject);//
        this.setFieldValByName(" batteryId", voPhone.getId() , metaObject);//
        this.setFieldValByName("cameraId", voPhone.getId() , metaObject);//
        this.setFieldValByName("socId", voPhone.getId() , metaObject);//
        this.setFieldValByName("performanceId", voPhone.getId(), metaObject);//*/
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("getModified", new Date(), metaObject);
    }
}
